package com.moon.jacocotestdemo.controller;

import com.moon.common.network.Json;
import com.moon.jacocotestdemo.test.AddTest;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/login")
public class loginController {
    @GetMapping(value = "/check",produces={"application/json;charset=utf-8"})
    @ResponseBody
    public String check(@RequestBody Map<String,Object> params){
        String userName = String.valueOf(params.get("userName"));
        String password = String.valueOf(params.get("password"));
        JSONObject res = new JSONObject();
        if(userName.equals("admin")&&password.equals("123456")){
            AddTest at = new AddTest();
            at.addTestOne();
            res.put("data","null");
            res.put("message","登录成功");
            res.put("success",true);
        }else if(password.equals("88888")){
            AddTest at = new AddTest();
            at.addTestTwo();
            res.put("data","使用万能密码登录");
            res.put("message","登录成功");
            res.put("success",true);
        }else{
            AddTest at = new AddTest();
            at.addTestThree();
            res.put("data","null");
            res.put("message","账号或密码错误");
            res.put("success",true);
        }
        return Json.jsonNull(res);
    }
}
